<!--
 * @description  :涉烟人员新增
 * @descriptionDetail:涉烟人员新增
 * @copyright    : 浙江烟草
 * @author       : dw
 * @create       : 2022-10-09 22:21:21
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :title="navTitle">
    </theme-navbar>
    <!-- #endif -->
    <view class="content content-bg ifn-content" style="background-color: white; margin-left='10rpx';padding-bottom:130rpx">
      <u-form
        class="u-form-m"
        :label-style="labelStyle"
        :model="baseInfo"
        :error-type="['border-bottom', 'message',]"
        label-width="auto"
        label-position="top"
        ref="uForm"
      >
        <u-form-item label="登记单位" :required="true">
          <u-input
            :disabled="true"
            placeholder="请选择"
            v-model="baseInfo.orgName"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="姓名" prop="name" :required="true" label-width="100rpx">
          <u-input
            v-model="baseInfo.name"
            :disabled="isDisabled"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="民族">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.NATION_LIST"
            :dicCode="baseInfo.nation"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('list',$u.dic.DIC_KEYS.NATION_LIST)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.nationName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'nationName', name)}"
            @click="showDic($u.dic.DIC_KEYS.NATION_LIST,baseInfo.nation,'list')"
          />
        </u-form-item>
        <u-form-item label="绰号">
          <u-input
            v-model="baseInfo.nickname"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="证件类型" :required="true" prop="idCardType">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.IDCARD_TYPE"
            :dicCode="baseInfo.idCardType"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('idCardType',$u.dic.DIC_KEYS.IDCARD_TYPE)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.idCardTypeName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'idCardTypeName', name)}"
            @click="showDic($u.dic.DIC_KEYS.IDCARD_TYPE,baseInfo.idCardType,'idCardType')"
          />
        </u-form-item>
        <u-form-item label="证件号码" prop="idCard" :required="true">
          <u-input
            v-model="baseInfo.idCard"
            :disabled="isDisabled"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="文化程度">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.L_EDU_LEVEL"
            :dicCode="baseInfo.education"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('education',$u.dic.DIC_KEYS.L_EDU_LEVEL)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.educationName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'educationName', name)}"
            @click="showDic($u.dic.DIC_KEYS.L_EDU_LEVEL,baseInfo.education,'education')"
          />
        </u-form-item>
        <u-form-item label="出生日期" prop="birthday">
          <u-calendar v-model="calendar.show" @change="change"></u-calendar>
          <u-input :disabled="true" placeholder="请选择" :custom-style="pointerStyle" v-model="baseInfo.birthday" @click="showa">
          </u-input>
        </u-form-item>
        <u-form-item label="性别" prop="sex">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.BSC_GENDDER"
            :dicCode="baseInfo.sex"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('sex',$u.dic.DIC_KEYS.BSC_GENDDER)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.sexName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'sexName', name)}"
            @click="showDic($u.dic.DIC_KEYS.BSC_GENDDER,baseInfo.sex,'sex')"
          />
        </u-form-item>
        <u-form-item label="身份证地址">
          <u-input
            v-model="baseInfo.idCardAddress"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="身高(cm)">
          <u-input
            v-model="baseInfo.height"
            type="number"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item prop="placeGis" label="工作单位">
          <u-input
            v-model="baseInfo.company"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="电话" prop="phone">
          <u-input
            v-model="baseInfo.phone"
            type="digit"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="现住址">
          <u-input
            v-model="baseInfo.realAddress"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="职业">
          <u-input
            v-model="baseInfo.duty"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="婚姻状态">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.T_PERSON_MARITAL_STATUS"
            :dicCode="baseInfo.maritalStatus"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('caseRole',$u.dic.DIC_KEYS.T_PERSON_MARITAL_STATUS)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.maritalStatusName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'maritalStatusName', name)}"
            @click="showDic($u.dic.DIC_KEYS.T_PERSON_MARITAL_STATUS,baseInfo.maritalStatus,'caseRole')"
          />
        </u-form-item>
        <u-form-item label="微信号">
          <u-input
            v-model="baseInfo.wechatAccount"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="QQ号">
          <u-input
            v-model="baseInfo.qqNo"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="支付宝">
          <u-input
            v-model="baseInfo.alipayAccount"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="邮箱" prop="email">
          <u-input
            v-model="baseInfo.email"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="零售许可证">
          <u-input
            v-model="baseInfo.licNo"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="涉烟角色" prop="caseRole">
          <dic-input
            :keyWord="$u.dic.DIC_KEYS.C_PARTYINFO_TYPE"
            :dicCode="baseInfo.caseRole"
            :border="false"
            type="select"
            :select-open="dicSelectOpen('caseRole',$u.dic.DIC_KEYS.C_PARTYINFO_TYPE)"
            placeholder="请选择"
            :disabled="true"
            v-model="baseInfo.caseRoleName"
            @changeInputModelData="(name)=>{$set(baseInfo, 'caseRoleName', name)}"
            @click="showDic($u.dic.DIC_KEYS.C_PARTYINFO_TYPE,baseInfo.caseRole,'caseRole')"
          />
        </u-form-item>
        <u-form-item label="籍贯" prop="personProvCityCountyName">
          <view style="display: flex; flex-direction: column;width: 100%;">
            <u-input
              type="select"
              :disabled="true"
              placeholder="请选择籍贯"
							:custom-style="pointerStyle"
              v-model="baseInfo.personProvCityCountyName"
              @click=" (nativeNameSelectShow = true)"
            ></u-input>
          </view>
        </u-form-item>
        <u-form-item label="详细地址">
          <u-input
            v-model="baseInfo.nativeAddress"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
        <u-form-item label="备注" :border-bottom="false">
          <u-input
            v-model="baseInfo.remark"
            type="textarea"
            placeholder="请输入"
          >
          </u-input>
        </u-form-item>
      </u-form>
      <view class="u-form">
        <u-gap :height="$theme.cm_section_top_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
        <fsection :title="title.images" :customStyle="customStyle"></fsection>
      </view>
      <view class="u-form-m pl-10">
        <m-upload
          :uploadParam="fileUploadParam"
          upApiUrl="uploadBase64ForApp"
          :fileList="fileList"
          @on-list-change="changeUpload"
        ></m-upload>
      </view>
    </view>
    <view class="submit-btns bottom-btns ">
      <u-button class="del" type="primary" @click="submit">
        保&nbsp;&nbsp;&nbsp;&nbsp;存
      </u-button>
    </view>
    <!-- 所在地  -->
    <u-popup mode="bottom" height="80%" v-model="nativeNameSelectShow">
      <area-select @choose="nativeNameSelectShowComfir"></area-select>
    </u-popup>
    <!-- 组织机构选择 -->
    <u-popup mode="bottom" height="80%" v-model="orgSelectShow">
      <org-select :cleanParentOrg="true" :isHybrid="true" limitNodeType="all" treeType="zm-comp" @choose="handlerChooseOrg"></org-select>
    </u-popup>
    <!-- 字典单选 -->
    <dic-choice
      :keyWord="dicKeyWords"
      :currentSelect="dicCurrentSelect"
      v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
  </view>
</template>

<script>
import areaSelect from "@/components/area-select.vue";
import DicInput from "@/components/dic_input.vue";
import DicChoice from "@/components/dic_choice.vue";
import OrgSelect from "@/components/org-select.vue";
import intelligenceservice from "@/service/intelligence/intelligence.service";
import MUpload from "@/components/m-upload.vue";
import {uuid,} from '@/common/util.js';
import certificateService from "@/service/certificate/certificate.service.js";
import fsection from "@/components/form-section.vue";
import {L_BSC_IDCARD_TYPE,} from "@/service/intelligence/mapping/enum.js";
export default {
  components: {
    areaSelect,
    OrgSelect,
    DicChoice,
    DicInput,
    MUpload,
    fsection,
  },
  data() {
    return {
      customStyle:{
        padding:"20rpx 32rpx",
      },
      rules:{
        name: [{
          required: true,
          message: '请输入姓名',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },{
          message:"姓名格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(value)){
              return true;
            }{
              let regs = /^[a-zA-Z\u4e00-\u9fa5]+$/;
              return regs.test(value);
            }
          },
        },],
        idCardType: [{
          required: true,
          message: '请选择证件类型',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },],
        idCard: [{
          required: true,
          message: '请输入证件号码',
          // 可以单个或者同时写两个触发验证方式
          trigger: ['change', 'blur',],
        },{
          message:"证件格式不正确！",
          trigger: ['change', 'blur',],
          validator: () => {
            if (this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.IDCARD) {
              // 身份证号
              let regs = /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}[0-9Xx]$)/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.PASSPORT){
              // 护照
              let regs = /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/;  // 护照（包括香港和澳门）
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.OTHER){
              // 其他证件
              let regs = /^[0-9a-zA-Z]*$/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.DRIVER){
              // 驾照
              let regs = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}(\d|x|X)$/;
              return regs.test(this.baseInfo.idCard);
            }else if(this.baseInfo.idCardType == L_BSC_IDCARD_TYPE.RESIDENCE_BOOKLET){
              // 户口簿
              let regs = /^[a-zA-Z0-9]{3,21}$/;
              return regs.test(this.baseInfo.idCard);
            }else{
              return true;
            }
          },
        },],
        email: [{
          message:"邮箱格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(value)){
              return true;
            }{
              return this.$u.test.email(value);
            }
          },
        },],
        caseMoney: [{
          message:"金额格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(value)){
              return true;
            }{
              return this.$u.test.amount(value);
            }
          },
        },],
        phone: [{
          message:"电话格式不正确！",
          trigger: ['change', 'blur',],
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(value)){
              return true;
            }{
              return this.$u.test.mobile(value) || this.$u.test.tel(value);
            }
          },
        },],
      },
      fileUploadParam:{
        fiGroupCode:this.$FILE_GROUP_TYPE.k_person_attr,
        bizId:"",
      },
      baseInfo: {
        alipayAccount: "",
        birthday: "",
        caseMoney: "",
        caseRole: "",
        caseRoleName:"",
        company: "",
        duty: "",
        education: "",
        email: "",
        height: "",
        idCard: "",
        idCardAddress: "",
        idCardType: "",
        idCardTypeName:"",
        licNo: "",
        maritalStatus: "",
        menuCode: null,
        name: "",
        nation: "",
        nativeAddress: "",
        nativeCityCode: "",
        nativeCountyCode: "",
        nativeProvCode: "",
        nickname: "",
        orgUuid: "",
        orgName:"",
        personProvCityCounty: [],
        personProvCityCountyName:"",
        phone: "",
        qqNo: "",
        realAddress: "",
        remark: "",
        sex: "",
        sexName:"",
        wechatAccount: "",
      },
      labelStyle: {
        fontWeight: 400,
        color: this.$theme.u_main_color,
        fontSize: '.75rem',
      },
      iconstlye: {
        'fontSize': '40rpx',
        'color': this.$theme.u_type_primary,
      },
      title:{
        images:"图片信息",
        tag:"标签信息",
        connectMsg:"涉案人员新增",
      },
      tagmsg:[],
      calendar:{
        show:false,
      },
      from:"add",
      orgSelectShow: false,
      nativeNameSelectShow: false,
      dicKeyWords: "",
      dicCurrentSelect:"",
      dicShow: false,
      user: this.$storage.get(this.$rp.common.USER),
      fileList:[],
      uuid:"",
      isDisabled:false,
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
			pointerStyle: {
			  marginRight: "5px",
				pointerEvents: "none !important"
			},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
    }
  },
  onLoad(opt) {
    this.from = opt.from;
    this.showDefaultTitle = false;
    if(this.from === "edit"){
      let title = "涉烟人员修改";
      this.updateMixinTitle(title);
      this.isDisabled = false;
      this.baseInfo = this.getRouteParam();
      this.fileUploadParam.bizId = this.baseInfo.uuid;
      if(this.$u.test.isEmpty(this.baseInfo.nativeCityCodeName)){
        this.baseInfo.personProvCityCountyName = ""
      }else{
        this.baseInfo.personProvCityCountyName = this.baseInfo.nativeProvCodeName +  this.baseInfo.nativeCityCodeName  + this.baseInfo.nativeCountyCodeName;
      }
    } else {
      let title = "涉烟人员新增";
      this.updateMixinTitle(title);
      this.baseInfo.uuid = uuid();
      this.fileUploadParam.bizId = this.baseInfo.uuid;
      if(this.user.orgLevel === 1){
        this.baseInfo.orgName = this.user.provOrgName;
        this.baseInfo.orgUuid = this.user.provOrgUuid;
      }else{
        this.baseInfo.orgName = this.user.townOrgName;
        this.baseInfo.orgUuid = this.user.townOrgUuid;
      }
    }
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);

  },
  onload(){
    this.tagmsg = this.updateBackState();
  },
  created(){
    this.initAuditImage();
  },
  mounted(){
  },
  methods: {
    getListViewTop(){
      this.$u.getRect('.case-search-lay').then(res => {
        this.listViewTop = (this.$u.sys().statusBarHeight + res.top + res.height) + 'px';
      });
      this.$u.getRect('.submit-btns').then(res => {
        this.bottomOffset = (this.$u.sys().screenHeight - res.top) + "px";
      });
    },
    initAuditImage(){
      certificateService.goFiles(this.baseInfo.uuid,this.$FILE_GROUP_TYPE.k_person_attr).then(res => {
        if(res.success) this.fileList = res.data;
      }).catch(e => {
        console.log(e);
      })
    },
    // 上传/删除图片事件
    changeUpload(list, key){
      if(list.length > 0){
        this.fileList = [...list,];
      }else{
        this.fileList = [];
      }
    },
    nativeNameSelectShowComfir(areas) {
      if(this.$modal.isMuniCity(areas[0].proCode)){
        this.baseInfo.personProvCityCountyName = [areas[0].admdivName, areas[0].countryName,].join("");
      }else{
        this.baseInfo.personProvCityCountyName = [areas[0].proName, areas[0].admdivName, areas[0].countryName,].join("");
      }
      this.baseInfo.nativeProvCode = areas[0].proCode;
      this.baseInfo.nativeCityCode = areas[0].admdivCode;
      this.baseInfo.nativeCountyCode = areas[0].countryCode;
      this.nativeNameSelectShow = false;
    },
    handlerChooseOrg(orgs) {
      this.baseInfo.orgUuid = orgs[0].id;
      this.baseInfo.orgName = orgs[0].name;
      this.orgSelectShow = false;
    },
    selectDicConfirm(e) {
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.IDCARD_TYPE) { // 证件类型
        this.baseInfo.idCardTypeName = e[0].label;
        this.baseInfo.idCardType = e[0].extra.bcbCode;
      }
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.BSC_GENDDER) { // 性别
        this.baseInfo.sexName = e[0].label;
        this.baseInfo.sex = e[0].extra.bcbCode;
      }
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.C_PARTYINFO_TYPE) { // 涉案人员角色
        this.baseInfo.caseRoleName = e[0].label;
        this.baseInfo.caseRole = e[0].extra.bcbCode;
      }else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.NATION_LIST) { // 民族
        this.baseInfo.nationName = e[0].label;
        this.baseInfo.nation = e[0].extra.bcbCode;
      }else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.L_EDU_LEVEL) { // 文化程度
        this.baseInfo.educationName = e[0].label;
        this.baseInfo.education = e[0].extra.bcbCode;
      }else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.T_PERSON_MARITAL_STATUS) { // 婚姻状态
        this.baseInfo.maritalStatusName = e[0].label;
        this.baseInfo.maritalStatus = e[0].extra.bcbCode;
      }
    },
    dicSelectOpen(type, keyWords) {
      if (type == this.dicType) {
        if (this.dicKeyWords == keyWords && this.dicShow) {
          return true;
        }
        return false;
      }
    },
    showDic(key, cur, type) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
      this.dicType = type;
    },
    showa(){
      this.calendar.show = true;
    },
    change(e){
      this.baseInfo.birthday = e.result;
    },
    submit(){
      this.$refs.uForm.validate(valid => {
        if (valid) {
          let params = this.baseInfo;
          this.$modal.showLoading('保存中...');
          intelligenceservice.savepersonInfoPage(params).then(res => {
            this.$modal.hideLoading();
            if(res.success){
              this.baseInfo = res.data;
              this.backPrev({
                paramKey:'refresh',
                param:true,
              })
            }else{
              this.$u.toast(res.msg);
            }
          }).catch(err => {
            this.$modal.hideLoading();
            console.log(err);
            this.$u.toast("保存失败" + err)
          })
        } else {
          console.log('验证失败');
        }
      });
    },
    close(){
      this.$u.route('pages/intelligence/personInvolvedList');
    },
  },
}
</script>

<style scoped lang="scss">
@import "./add.scss";
.fsection{
    width: 75% !important;
}
.choice{
    position: relative;
    top:20rpx;
    float:right;
}
.tag{
   margin-right: 10rpx;
}
.page{
  padding: 0;
}
</style>
